using System;
using System.Security.Cryptography;
using System.Text;

namespace GoChat_for_Windows.Utils
{
    public static class PasswordUtils
    {
        public static string EncryptPassword(string password)
        {
            try
            {
                // 创建MD5加密对象
                using var md5 = MD5.Create();
                // 执行加密
                byte[] bytes = md5.ComputeHash(Encoding.UTF8.GetBytes(password));
                // 将字节数组转换为十六进制字符串
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < bytes.Length; i++)
                {
                    sb.Append(bytes[i].ToString("x2"));
                }
                return sb.ToString();
            }
            catch (Exception)
            {
                return password; // 如果加密失败，返回原始密码
            }
        }
    }
} 